package cn.gson.springmvc.commons;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Tool {

    /**将JSONArray格式化成和JPA实体类格式一样
     * @param jsonArray
     * @return
     */
    public JSONArray coumlnFormat(JSONArray jsonArray){
        String s = jsonArray.toJSONString();
        s = s.toLowerCase();
        Pattern p = Pattern.compile( "_([a-zA-Z])" );
        Matcher m = p.matcher( s );
        StringBuffer sb = new StringBuffer();
        while (m.find()) {
            m.appendReplacement(sb, m.group(1).toUpperCase());
        }
        m.appendTail(sb);
        JSONArray result= JSON.parseArray(sb.toString());
        return result;
    }
}
